﻿using System.Collections.ObjectModel;
using System.Xml.Serialization;
using PrearrangedChaos.AgileZen.Service.Rest;

namespace PrearrangedChaos.AgileZen.Service.Model
{
    /// <remarks/>
    [XmlType(AnonymousType = true)]
    [XmlRoot(ElementName = "phase", Namespace = "", IsNullable = false)]
    [ZenRestRequest("projects/{ProjectId}/phases/{PhaseId}", "projects/{ProjectId}/phases")]
    public partial class Phase : PhaseUpdater, IPhase
    {
        private IStory[] _stories;

        private string _name;

        /// <remarks/>
        [XmlElement(ElementName = "name")]
        public string Name
        {
            get { return _name; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                    _name = value;
                else
                    _name = null;
            }
        }

        public bool NameSpecified { get { return this.Name != null; } }

        [XmlArrayItemAttribute("story", IsNullable = false)]
        [XmlArray(ElementName = "stories")]
        public Story[] StoriesXmlElement
        {
            get { return _stories as Story[]; }
            set { _stories = value; }
        }

        [XmlIgnore]
        public ReadOnlyCollection<IStory> Stories
        {
            get { return new ReadOnlyCollection<IStory>(_stories ?? new Story[0]); }
        }
    }
}